home *** CD-ROM | disk | FTP | other *** search
- ;-- Display disk directory. Written by Tom Swan in Turbo Assembler.
-
- IDEAL ; Switch on Ideal mode
- %TITLE "DR.ASM" ; Comments allowed in titles!
- DOSSEG ; Use standard segments
- MODEL small ; 64K code; 64K data
- STACK 256 ; Reserve space for stack
-
- Attribute EQU 0 ; Attribute for DirSearch
- FileName EQU 30 ; Offset to file name in DTA
- Cr EQU 13 ; ASCII carriage return
- Lf EQU 10 ; ASCII line feed
-
- DATASEG
-
- FileSpec DB "*.*", 0 ; ASCIIZ (null-ending) string
- CrLf DB Cr, Lf, '$' ; Carriage return, line feed
- DTA DB 128 DUP (?) ; 128-byte unitialized buffer
-
- CODESEG
-
- Start:
- mov ax,@data ; Initialize DS to address
- mov ds,ax ; of data segment
- mov dx, OFFSET DTA ; Tell DOS to use our
- mov ah, 1ah ; disk transter area (DTA)
- int 21h ; Call DOS, assign DTA address
-
- mov bx, OFFSET ListDir ; Address ListDir subroutine
- mov cx, Attribute ; Assign attribute to cx
- mov dx, OFFSET FileSpec ; Address wild card string
- call DirSearch ; Search and list directory
-
- mov ax,04C00h ; End with exit code = 0
- int 21h ; Return to DOS
-
-
- ;-- Directory Search subroutine
- ; Input: bx = address of subroutine to call for each match
- ; cx = attribute(s) to match
- ; ds:dx = address of ASCIIZ wild card string, e.g. "*.PAS",0
-
- PROC DirSearch
- mov ah, 4eh ; Find-first function number
- jmp short @@t20 ; Jump into loop
- @@t10:
- mov ah, 4fh ; Find-next function number
- @@t20:
- int 21h ; Call DOS, find first/next
- jc @@t30 ; Exit when done
- call bx ; Call user subroutine
- jmp @@t10 ; Continue searching
- @@t30:
- ret ; Return to caller
- ENDP
-
-
- ;----- List directory entry subroutine
- ; Input: DTA contains one directory entry from DirSearch
-
- PROC ListDir
- cld ; Clear direction flag
- mov si, OFFSET DTA+FileName ; Address file name in DTA
- @@t10:
- lodsb ; al<-name[si]; si<-si+1
- or al, al ; Is al = 0?
- je @@t20 ; If al = 0, jump to exit
- mov ah, 2 ; Display-char function number
- mov dl, al ; Move char to dl
- int 21h ; Call DOS, print character
- jmp @@t10 ; Do next character
- @@t20:
- mov ah, 9 ; Display ASCII$ string
- mov dx, OFFSET CrLf ; Assign offset to CrLf string
- int 21h ; Call DOS, print string
- ret ; Return to caller
- ENDP
-
- END Start ; End of text. Program entry point.